Copy enumeration attribute values in objects in defferent modules

Hi,

I have to copy an object and all his attributes from the module A  to the module B. Let's call Xa the object in the module A and Xb the clone object in the module B. The two modules has the same attributes, but it can be that in the module B the value "jjj" of the enumeration attribute types "kkk" is not present

Is there a simple control that  when i try to assign Xb."kkk" = "jjj" the script doesn't crash, but it doesn't assign the value? Should i check for each attribute of each objects i want to copy that the attribute is an enumeration, for each value of the attribute that the value is present also in b?

I need to copy a huge amount of object, so i want to optimize the computation time.


bungle_77 - Mon Dec 02 06:33:15 EST 2013

Re: Copy enumeration attribute values in objects in defferent modules
GregM_dxler - Mon Dec 02 14:53:19 EST 2013

Hi,

What you need to do is check and verify the attribute value is valid first before you assign it.  Here is a snipet of code I used to check to see if an attribute value is valid or not.  sAN is the attribute name and sAV is the attribute value.  The curmod would have to be your module B.  If the value is not valid, it will write to the error log.  You can add in an else where you would then copy the attribute value in module B when it is valid.

               if (exists attribute sAN){ //check if the attribute is there
                  AttrDef ad = find(curmod, sAN) //get attribute name as a definition
                  if (!attributeValue(ad, sAV)) {
                     //value is invalid, so add to error log
                     sError_Log = sError_Log "Error, invalid attribute value"\n"
                     sError_Log = sError_Log "Attribute:" sAN ";  Value:" sAV ";\n"
                  }
               }

Hope this helps,

Greg

Re: Copy enumeration attribute values in objects in defferent modules
llandale - Thu Dec 05 13:59:19 EST 2013

First you can trap errors of many DXL commands:

  • noError()
  • o."MyAttr" = "Some Value"
  • string ErrMess = lastError()
  • if (!null ErrMess) then deal with the error

Too lazy to look myself, but google "CopyAtts.dxl", hopefully version 1.3 or greater.  It will push attr types and defs from one module to another.  It will not, I notice, REPLACE an existing attr, so make sure it is defined correctly before pushing.

-Louie

Re: Copy enumeration attribute values in objects in defferent modules
bungle_77 - Mon Dec 09 04:29:28 EST 2013

llandale - Thu Dec 05 13:59:19 EST 2013

First you can trap errors of many DXL commands:

  • noError()
  • o."MyAttr" = "Some Value"
  • string ErrMess = lastError()
  • if (!null ErrMess) then deal with the error

Too lazy to look myself, but google "CopyAtts.dxl", hopefully version 1.3 or greater.  It will push attr types and defs from one module to another.  It will not, I notice, REPLACE an existing attr, so make sure it is defined correctly before pushing.

-Louie

thanks both, you provided me two very yuseful instructions